<?
	function utf8_to_tis620($string)
	{
		$str = $string;
		$res = "";
		for ($i = 0; $i < strlen($str); $i++) {
		  if (ord($str[$i]) == 224) {
			$unicode = ord($str[$i+2]) & 0x3F;
			$unicode |= (ord($str[$i+1]) & 0x3F) << 6;
			$unicode |= (ord($str[$i]) & 0x0F) << 12;
			$res .= chr($unicode-0x0E00+0xA0);
			$i += 2;
		  } else {
			$res .= $str[$i];
		  }
		}
		return $res;
	}
	
	function utf8_substr($str,$start_p,$len_p) 
	{ 
		preg_match_all("/./u", $str, $ar); 
		
		if(func_num_args() >= 3) { 
			$end = func_get_arg(2); 
			return join("",array_slice($ar[0],$start_p,$len_p)); 
		} else { 
			return join("",array_slice($ar[0],$start_p)); 
		} 
	}
?>














